






//
//  NZhichengDetailViewController.m
//  nncloud
//
//  Created by macfai on 2018/11/28.
//  Copyright © 2018 macfai. All rights reserved.
//

#import "NZhichengDetailViewController.h"
#import "NZhichengDetailCell.h"
#import <WebKit/WebKit.h>
@interface NZhichengDetailViewController ()<UITableViewDataSource,UITableViewDelegate,WKUIDelegate,WKNavigationDelegate>

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataArray;


@end

@implementation NZhichengDetailViewController
#define cellIdentifier @"zhichengDetail"
#define SectionHeaderHeight  10.f

-(UITableView *)tableView{
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight - 64) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 486.f;
        _tableView.backgroundColor = kBackgroundColor;
        [_tableView registerNib:[UINib nibWithNibName:@"NZhichengDetailCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        _tableView.showsVerticalScrollIndicator = NO;
        //        _tableView.tableFooterView = [UIView new];
        
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;
    [self.navigationItem setItemWithTitle:@"职称评审详情" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    [self.view addSubview:self.tableView];
    
    // Do any additional setup after loading the view from its nib.
}


#pragma mark - datasource

//-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//
//    return 1;
//
//}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NZhichengDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    
//    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(25, 120, ScreenWidth-50, 350)];
//    view.backgroundColor = kMagentaColor;
//    [cell addSubview:view];
    
    WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(25, 120, ScreenWidth-50, 350)];
    [cell addSubview:webView];
    webView.UIDelegate = self;
    webView.navigationDelegate = self;
    ///直接加载html 语句
    [webView loadHTMLString:self.model.titleEvaluationContent baseURL:nil];
    cell.name.text = self.model.titleEvaluationTitle;
    cell.time.text = [ToolKit getTimeFromTimesTamp:self.model.titleEvaluationUpdateTime];
    
//    NSString *content = [self flattenHTML:self.model.titleEvaluationContent];
    
//    content = [content stringByReplacingOccurrencesOfString:@"&" withString:@""];
//    cell.content.text = [content stringByReplacingOccurrencesOfString:@"gt;" withString:@""];
//    cell.content.text = content;
    return cell;
}

- (void)addWebView
{
    WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:webView];
    webView.UIDelegate = self;
    webView.navigationDelegate = self;
    NSString *strHTML = @"<p><strong>很经典的黑色后背纯雪纺透视装到货了哈</strong><strong>&nbsp;</strong></p><p><strong>前面莫代尔&nbsp;手感顺滑 柔软 &nbsp;手感不错</strong></p><p><strong>后面薄薄的雪纺纱</strong></p><p><strong>腰节处开叉</strong></p><p><strong>很大气，超有范儿的一款&nbsp; 这个年代随时随地 都可见的欧美街头范儿</strong></p><p><strong>后背透、透、透</strong></p><p><strong>165身高 96J穿起来大概在膝盖不到10CM的位置</strong></p><p>&nbsp;</p><p><strong>亲们啊~ 特别美得一款，穿起来超级有范，</strong></p><p><strong>看着特别不起眼的一件衣服，但上身效果特别好，</strong></p><p><strong>背面全部透视的雪纺黑纱，特别性感，</strong></p><p><strong>里面需要配一款黑色吊带，两侧带开叉的设计，亲们赶紧下手吧~~&middot;</strong></p><p>&nbsp;</p><p><strong>面料： 正面莫代尔背面：雪纺纱&nbsp;</strong></p><p><strong>Label:</strong>无主标 无尺码标&nbsp; 有吊牌 普通包装</p><p>&nbsp;</p><p><strong>Size</strong>：平铺尺寸,由于手工测量,会有2~3厘米的误差</p><p>~SIZE=CM</p><p>胸围：126连肩袖长：65&nbsp; 前衣长：80 后衣长：90</p><p>&nbsp;<img style=\"border-width:0;border-image-width:initial\" src=\"https://img.alicdn.com/imgextra/i4/676496646/T2zdB0X9NXXXXXXXXX_!!676496646.jpg\" width=\"100%\" height=\"((348 / 500) * 100)%\" align=\"absmiddle\">&nbsp;&nbsp;</p><p>&nbsp;</p>";
    [webView loadHTMLString:strHTML baseURL:nil];
    
}

///两种方法方法1过滤标签     方法2直接用webview加载html的语句，这样样式就也可以进行解决了

///方法1过滤掉h5的标签内容
- (NSString *)flattenHTML:(NSString *)html {
    NSScanner *theScanner;
    NSString *text = nil;
    theScanner = [NSScanner scannerWithString:html];
    
    while ([theScanner isAtEnd] == NO) {
        // find start of tag
        [theScanner scanUpToString:@"<" intoString:NULL] ;
        // find end of tag
        [theScanner scanUpToString:@">" intoString:&text] ;
        // replace the found tag with a space
        //(you can filter multi-spaces out later if you wish)
        html = [html stringByReplacingOccurrencesOfString:
                [NSString stringWithFormat:@"%@>", text]
                                               withString:@""];
    }
    return html;
}



#pragma mark - delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}


#pragma mark - section head
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return SectionHeaderHeight;//如果设置section的header高度，不设置footer高度，footer默认等于header高度
}



- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SectionHeaderHeight)];
    view.backgroundColor = kBackgroundColor;
    return view;
}

#pragma mark - section foot
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}

#pragma mrak - wkwebview delegate
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
    //修改字体大小 300%
    [ webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '250%'" completionHandler:nil];
    
    //修改字体颜色  #9098b8
//    [ webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= '#0078f0'" completionHandler:nil];
    
}


@end
